package mutilthread;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created with IntelliJ IDEA.
 * Description: 定时器的实现. TimerTask 基于 Runnable 实现
 * User: Li_yizYa
 * Date: 2025—04—01
 * Time: 19:51
 */
public class Demo21 {
    public static void main(String[] args) {
        Timer timer = new Timer();
        //含义：在 3s 后执行 hello 的打印
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello3");
            }
        }, 3000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello2");
            }
        }, 2000);

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello1");
            }
        }, 1000);

        System.out.println("程序开始执行");
    }
}
